package com.wanglianyun.config.datasource;

import com.alibaba.druid.pool.DruidDataSource;
import com.baomidou.mybatisplus.core.MybatisConfiguration;
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.ibatis.logging.stdout.StdOutImpl;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.sql.DataSource;

/**
 * Description:
 * Copyright: Copyright (c) 2024
 * Create Time: 2024-11-13 13:50
 *
 * @author wanglianyun
 */
//@Configuration
//@EnableAutoConfiguration
//@MapperScan(basePackages = "com.wanglianyun.mapper.db2", sqlSessionFactoryRef = "sqlSessionFactoryTwo")
//public class DataSourceTeacherConfiguration {
//
//    @Value("${spring.datasource.type}")
//    private Class<? extends DataSource> dataSourceType;
//
//    @Value("${spring.datasource.druid-pool.initial-size}")
//    private int initialSize;
//    @Value("${spring.datasource.druid-pool.max-active}")
//    private int maxActive;
//    @Value("${spring.datasource.druid-pool.max-wait}")
//    private int maxWait;
//    @Value("${spring.datasource.druid-pool.min-idle}")
//    private int minIdle;
//
//    @Bean("dataSourceTwo")
//    @ConfigurationProperties(prefix = "spring.datasource.db2")
//    public DataSource dataSourceTwo() {
//        DruidDataSource druidDataSource = (DruidDataSource) DataSourceBuilder.create().type(dataSourceType).build();
//        druidDataSource.setMaxActive(maxActive);
//        druidDataSource.setMaxWait(maxWait);
//        druidDataSource.setInitialSize(initialSize);
//        druidDataSource.setMinIdle(minIdle);
//        return druidDataSource;
//    }
//
//    @Bean("sqlSessionFactoryTwo")
//    public SqlSessionFactory getSqlSessionFactoryTwo(@Qualifier("dataSourceTwo") DataSource dataSourceTwo) throws Exception {
//        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        mybatisSqlSessionFactoryBean.setDataSource(dataSourceTwo);
//        mybatisSqlSessionFactoryBean.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:mapper/db2/*.xml"));
//        MybatisConfiguration mybatisConfiguration = new MybatisConfiguration();
//        mybatisConfiguration.setLogImpl(StdOutImpl.class);
//        mybatisSqlSessionFactoryBean.setConfiguration(mybatisConfiguration);
//        return mybatisSqlSessionFactoryBean.getObject();
//    }
//
//    @Bean("sqlSessionTemplateTwo")
//    public SqlSessionTemplate getSqlSessionTemplateTwo(@Qualifier("sqlSessionFactoryTwo") SqlSessionFactory sqlSessionFactoryTwo) throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactoryTwo);
//    }
//}
